package com.yangfan.springcloud.controller;


import com.yangfan.springcloud.entities.CommonResult;
import com.yangfan.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;


/**
 * 使用RestTemplate进行远程调用
 */

@RequestMapping(value = "/order")
@RestController
@Slf4j
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;
    private static final String URL = "http://CLOUD-PAYMENT-SERVICE";


    @PostMapping(value = "/consumer/payment/create")
    public CommonResult<Payment> create(Payment payment){
        log.info("create运行了");
        return restTemplate.postForObject(URL+"/payment/create",payment,CommonResult.class);
    }



    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> get(@PathVariable(value = "id") Long id){
        log.info("get运行了");
        return restTemplate.getForObject(URL+"/payment/getPaymentById/"+id,CommonResult.class);
    }





}
